package cn.xiqi.cms.oper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import cn.xiqi.cms.action.BaseAction;
import cn.xiqi.cms.hibernate.DAO.LogDAOImpl;
import cn.xiqi.cms.hibernate.beans.Loginfo;
import cn.xiqi.cms.hibernate.service.LogService;
import cn.xiqi.cms.hibernate.service.LogServiceImpl;

public class LogOper {
	private LogService service;
	
	public LogOper(){
		service = new LogServiceImpl();
		service.setDao(new LogDAOImpl());
	}
	
	public boolean saveLog(int type, int usrID, String stime, String content){
		boolean b = true;
		Date logtime;
		SimpleDateFormat sdf = new SimpleDateFormat(BaseAction.TIMEFOEMAT);
		
		try{
			logtime = sdf.parse(stime);
			service.add(type, usrID, logtime, content);
		}catch(Exception e){
			b = false;
		}
		return b;
	}
	
	public List<Loginfo> getAll(int page, int size){
		List<Loginfo> infos;
		
		infos = service.getAll(page, size);
		return infos;
	}
	
	public List<Loginfo> getByUsr(int usrid, int page, int size){
		List<Loginfo> infos;
		
		infos = service.getByUsr(usrid, page, size);
		return infos;
	}
	
	public List<Loginfo> getByType(int type, int page, int size){
		List<Loginfo> infos;
		
		infos = service.getByType(type, page, size);
		return infos;
	}
	
	public List<Loginfo> getByTime(Date start, Date end, int page, int size){
		List<Loginfo> infos;
		
		infos = service.getByTime(start, end, page, size);
		return infos;
	}
}
